<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>立即执行函数 IIFE</title>
</head>
<body>
    <script>
        const Counter = (function() {
            let count = 0; // 自由变量 私有
            function increment() {
                return ++count;
            }
            function reset() {
                count = 0;
            }
            return function() {
                return {
                    getCount: function() {
                        return count;
                    },
                    increment: function() {
                        return increment();
                    },
                    reset: function() {
                        reset();
                    }
                }
            }
        })();
        const counter = Counter();
        console.log(counter.getCount());
    </script>
</body>
</html>